/**
 * 
 */
package ch.rouce.smonkey.panel;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;

import javax.swing.JPanel;

/**
 * @author Bopp
 *
 */
public class Board extends JPanel implements Runnable {

	
	private long sleep;
	private long diff;
	private long beforeTime;
	private long currentTime;
	private long fps = 25;
	private long ticks = 1000 / fps;
	public static boolean END = false;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Board(){
		setDoubleBuffered(true);
		new Thread(this).start();
	}
	
	
	public void paint(Graphics g1){
		super.paint(g1);
		Graphics2D g = (Graphics2D)g1;
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
		
		g.setBackground(Color.white);
		
		Toolkit.getDefaultToolkit().sync();
		g.dispose();
	}


	@Override
	public void run() {
		if(!END)
			new Thread(this).start();
		currentTime = System.currentTimeMillis();
		
		repaint();
		
		beforeTime = currentTime;
		
		sleep = ticks - beforeTime;
	}
}
